/*
 * @(#)com.cloud.lan.service.task 2022/2/25 15:26
 * @Author <a href="mailto:xyqierkang@gmail.com">ErKang Qi</a>
 * @Blog：https://www.qekang.com
 * Copyright (c) 2019-2022 Shanghai
 * All rights reserved.

 * This software is the confidential and proprietary information of
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 */
package com.cloud.lan.service.task;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * ewu
 * @author ErKang
 * @date Created in 2022/2/25 15:26
 * @title EwuMesTask.java
 * Department: Product development
 */
@Component
@Configuration
@Slf4j
@EnableScheduling
public class EwuMesTask {

    private static final String EWU_NEW = "https://interface.sina.cn/wap_api/common_timeline.d.json?url=mcwiwss2660206";

    @Value("${spring.profiles.active}")
    private String active;

//    public static void main(String[] args) {
//        try {
//            JSONObject obj = JSONUtil.parseObj(HttpUtil.get(EWU_NEW));
//            String code = obj.getJSONObject("result").getJSONObject("status").getStr("code");
//            String meta = obj.getJSONObject("result").getJSONObject("data").getJSONObject("meta").getStr("title");
//            if (ZERO.getKey().equals(Integer.parseInt(code))) {
//                JSONObject data = obj.getJSONObject("result").getJSONObject("data");
//                StringBuffer tcMsg = new StringBuffer();
//                for (int i = 0; i < 5; i++) {
//                    Object content = data.getJSONArray("data").get(i);
//                    JSONObject ms = JSONUtil.parseObj(content);
//                    JSONObject info = ms.getJSONObject("item").getJSONObject("info");
//                    String msCon = info.getStr("title");
//                    String time = info.getStr("showTimeText");
//                    String tc = StrUtil.format("最新内容,{},报道时间 {} \r \n ", msCon, time);
//                    tcMsg.append("\r \n " + tc + "\r \n");
//                }
//                TalkUtil.DingTalk(meta, tcMsg.toString());
//                log.info("#定时任务 完成，主推内容 meta {} tc {}", meta, tcMsg.toString());
//            }
//        } catch (Exception e) {
//            log.error("#定时任务 错误 :", e);
//        }
//    }

    /**
     * 每*分钟执行一次
     */
//    @Scheduled(cron = "0 0/1 * * * ?")
//    private void ewuTask() {
//        try {
//            if (true) {
//                log.info("# ewuTask push not env test");
//                return;
//            }
//            JSONObject obj = JSONUtil.parseObj(HttpUtil.get(EWU_NEW));
//            String code = obj.getJSONObject("result").getJSONObject("status").getStr("code");
//            String meta = obj.getJSONObject("result").getJSONObject("data").getJSONObject("meta").getStr("title");
//            if (ZERO.getKey().equals(Integer.parseInt(code))) {
//                JSONObject data = obj.getJSONObject("result").getJSONObject("data");
//                StringBuffer tcMsg = new StringBuffer();
//                for (int i = 0; i < 5; i++) {
//                    Object content = data.getJSONArray("data").get(i);
//                    JSONObject ms = JSONUtil.parseObj(content);
//                    JSONObject info = ms.getJSONObject("item").getJSONObject("info");
//                    String msCon = info.getStr("title");
//                    String time = info.getStr("showTimeText");
//                    String tc = StrUtil.format("最新内容,{},报道时间 {} \r \n ", msCon, time);
//                    tcMsg.append("\r \n " + tc + "\r \n");
//                }
//                TalkUtil.DingTalk(meta, tcMsg.toString());
//                log.info("#ewuTask push success");
//            }
//        } catch (Exception e) {
//            log.error("#定时任务 错误 :", e);
//        }
//    }
}
